package com.ym.b2b.commons.dao;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.ibatis.sqlmap.client.SqlMapClient;

public abstract class BaseDao<T> {

    protected SqlMapClientTemplate sqlMapClient = new SqlMapClientTemplate();

    protected Logger               logger       = Logger.getLogger(getClass());

    @Resource
    public void setSqlMapClient(SqlMapClient sqlMapClient) {
        this.sqlMapClient.setSqlMapClient(sqlMapClient);
    }

    protected Object insert(String sql_id, Object param) throws DataAccessException {
        sqlMapClient.insert(sql_id, param);
        return true;
    }

    protected int update(String sql_id, Object param) throws DataAccessException {
        return sqlMapClient.update(sql_id, param);
    }

    protected int delete(String sql_id, Object id) throws DataAccessException {
        return sqlMapClient.delete(sql_id, id);
    }

    protected Object find(String sql_id, Object query) throws DataAccessException {
        return sqlMapClient.queryForObject(sql_id, query);
    }

    protected Object listNum(String sql_id, Object query) throws DataAccessException {
        return sqlMapClient.queryForObject(sql_id, query);
    }

    @SuppressWarnings("rawtypes")
    protected List list(String sql_id, Object query) throws DataAccessException {
        return sqlMapClient.queryForList(sql_id, query);
    }

    public SqlMapClientTemplate getSqlMapClientTemplate() {
        return sqlMapClient;
    }

}
